package cards;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;

enum Face {A, KING};
enum Suit {HEARTS, CLUBS};

class Card implements Serializable
{
    public Card(Suit s, Face f)
    {
        face = f;
        suit = s;
    }
    private Face face;
    private Suit suit;
    
    @Override
    public String toString()
    {
        return face.toString() + suit.toString();
    }
    
    private void writeObject(ObjectOutputStream s) throws IOException {
        s.writeInt( face.ordinal() );     
        s.writeInt( suit.ordinal() );
    }
    
    private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
        face = Face.values()[s.readInt()];
        suit = Suit.values()[s.readInt()];
    }
}

public class Cards {


    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ArrayList<Card> list = new ArrayList<>();
        list.add( new Card(Suit.CLUBS, Face.A ));
        
        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream(new File("cards.bin")));
        
        oos.writeObject( list );
        
        ObjectInputStream ois = new ObjectInputStream(
                new FileInputStream(new File("cards.bin")));
        
        ArrayList<Card> list2 = new ArrayList<>();
        list2 = (ArrayList<Card>)ois.readObject( );
        
        for ( Card c : list2)
            System.out.println(c);
        
    }
}
